using System;
using System.Collections.Generic;
using System.Linq;

namespace Corelib.Entities
{
	[Table(Name = "dbo.Person")]
	public class Person
	{

		#region Private Data Members

		private int  _personID;
		private string  _title;
		private string  _firstName;
		private string  _lastName;
		private DateTime  _createDate;
		private DateTime  _modifyDate;

		#endregion

		#region Private "Static" Data Members

		private static readonly string[] _propertyNames = new string[] {
			"PersonID",
			"Title",
			"FirstName",
			"LastName",
			"CreateDate",
			"ModifyDate",
		};

		#endregion

		#region Constants

		public const int 
			FieldPersonIDIdx = 0,
			FieldTitleIdx = 1,
			FieldFirstNameIdx = 2,
			FieldLastNameIdx = 3,
			FieldCreateDateIdx = 4,
			FieldModifyDateIdx = 5;

		#endregion

		#region Private instance data members

		private FieldInfo[] _fieldInfo = new FieldInfo[]{
			new FieldInfo(FieldPersonIDIdx,FieldType.Primitive),
			new FieldInfo(FieldTitleIdx,FieldType.Primitive),
			new FieldInfo(FieldFirstNameIdx,FieldType.Primitive),
			new FieldInfo(FieldLastNameIdx,FieldType.Primitive),
			new FieldInfo(FieldCreateDateIdx,FieldType.Primitive),
			new FieldInfo(FieldModifyDateIdx,FieldType.Primitive),
		};

		#endregion

		#region Public Properties

		[Column(DBType = "int not null")]
		public int PersonID
		{
			get { return this.GetHelper(_fieldInfo, _propertyNames, FieldPersonIDIdx,  _personID); }
			set {  _personID = this.SetValueTypeHelper(_fieldInfo, FieldPersonIDIdx,  _personID, value,  _personID == value); }
		}

		[Column(DBType = "nvarchar(5) null")]
		public string Title
		{
			get { return this.GetHelper(_fieldInfo, _propertyNames, FieldTitleIdx,  _title); }
			set {  _title = this.SetValueTypeHelper(_fieldInfo, FieldTitleIdx,  _title, value,  _title == value); }
		}

		[Column(DBType = "nvarchar(50) null")]
		public string FirstName
		{
			get { return this.GetHelper(_fieldInfo, _propertyNames, FieldFirstNameIdx,  _firstName); }
			set {  _firstName = this.SetValueTypeHelper(_fieldInfo, FieldFirstNameIdx,  _firstName, value,  _firstName == value); }
		}

		[Column(DBType = "nvarchar(50) null")]
		public string LastName
		{
			get { return this.GetHelper(_fieldInfo, _propertyNames, FieldLastNameIdx,  _lastName); }
			set {  _lastName = this.SetValueTypeHelper(_fieldInfo, FieldLastNameIdx,  _lastName, value,  _lastName == value); }
		}

		[Column(DBType = "datetime not null")]
		public DateTime CreateDate
		{
			get { return this.GetHelper(_fieldInfo, _propertyNames, FieldCreateDateIdx,  _createDate); }
			set {  _createDate = this.SetValueTypeHelper(_fieldInfo, FieldCreateDateIdx,  _createDate, value,  _createDate == value); }
		}

		[Column(DBType = "datetime null")]
		public DateTime ModifyDate
		{
			get { return this.GetHelper(_fieldInfo, _propertyNames, FieldModifyDateIdx,  _modifyDate); }
			set {  _modifyDate = this.SetValueTypeHelper(_fieldInfo, FieldModifyDateIdx,  _modifyDate, value,  _modifyDate == value); }
		}

		#endregion
	}
}
